var app = getApp(),
  utils = getApp().helper,
  api = getApp().api;

Page({
  data: {
    isPageShow: !1,
    order: null,
    getGoodsTotalPrice: function() {
      return this.data.order.total_price;
    },
    hide: 1,
    qrcode: "",
    delivery_type:0
  },
  onLoad: function(e) {
    getApp().page.onLoad(this, e);
    if (!e.id && e.scene) {
      var t = decodeURIComponent(e.scene);
      if (void 0 !== t) {
        var a = utils.scene_decode(t);
        this.setData({
          order_id:a.order_id,
          delivery_type: a.delivery_type
        });
        a.order_id && (this.wancheng(a.order_id));
        return;
      }
    }
    var t = this;
    getApp().core.showLoading({
      title: "正在加载"
    });
    var o = getCurrentPages(),
      a = o[o.length - 2];
    t.setData({
      delivery_type: e.delivery_type
    });
    getApp().request({
      url: getApp().api.order.de_detail,
      data: {
        order_id: e.id,
        route: a && a.route ? a.route : '',
        delivery_type: e.delivery_type
      },
      success: function(e) {
        0 == e.code && t.setData({
          order: e.data,
          isPageShow: !0
        });
      },
      complete: function() {
        getApp().core.hideLoading();
      }
    });
  },
  copyText: function(e) {
    var t = e.currentTarget.dataset.text;
    getApp().core.setClipboardData({
      data: t,
      success: function() {
        getApp().core.showToast({
          title: "已复制"
        });
      }
    });
  },

  copyinfo: function (e) {
    this.currentPage;
    getApp().core.setClipboardData({
      data: e.target.dataset.info,
      success: function (e) {
        getApp().core.showToast({
          title: "复制成功！",
          icon: "success",
          duration: 2e3,
          mask: !0
        });
      }
    });
  },
  deSubmit: function(y) {
    var th = this;
    getApp().request({
      url: getApp().api.order.peisong,
      data: {
        oid: y.target.dataset.oid,
        delivery_type: th.data.delivery_type,
        status: y.target.dataset.status
      },
      success: function(t) {
        if (t.code == 0) {
          wx.redirectTo({
            url: '/delivery/delivery_order_detail/delivery_order_detail?id=' + y.target.dataset.oid + '&&delivery_type=' + th.data.delivery_type
          });

        }
      }
    })
  },

  wancheng: function(order_id) {
    var a = this;
    getApp().request({
      url: getApp().api.order.delivery_order_confirm,
      data: {
        order_id: order_id,
        status: 3,
        delivery_type: a.data.delivery_type
      },
      success: function (t) {
        wx.showModal({
          title: '订单收货',
          content: t.msg,
          showCancel: false, //是否显示取消按钮
          confirmText: "确定", //默认是“确定”
          // confirmColor: 'skyblue', //确定文字的颜色
          success: function (res) {
            //点击确定
            wx.redirectTo({
              url: t.data,
            });
          }
        })
      }
    })
  },
  location: function() {
    var e = this.data.order.shop;
    getApp().core.openLocation({
      latitude: parseFloat(e.latitude),
      longitude: parseFloat(e.longitude),
      address: e.address,
      name: e.name
    });
  },
  orderRevoke: function(t) {
    var o = this;
    getApp().core.showModal({
      title: "提示",
      content: "是否退款该订单？",
      cancelText: "否",
      confirmText: "是",
      success: function(e) {
        if (e.cancel) return !0;
        e.confirm && (getApp().core.showLoading({
          title: "操作中"
        }), getApp().request({
          url: getApp().api.order.revoke,
          data: {
            order_id: t.currentTarget.dataset.id
          },
          success: function(e) {
            getApp().core.hideLoading(), getApp().core.showModal({
              title: "提示",
              content: e.msg,
              showCancel: !1,
              success: function(e) {
                e.confirm && o.onLoad({
                  id: o.data.order.order_id
                });
              }
            });
          }
        }));
      }
    });
  },
  orderQrcode: function(a) {
    var o = this,
      r = a.target.dataset.oid;
    wx.showLoading({
      title: "正在加载",
      mask: !0
    }), getApp().request({
      url: getApp().api.user.get_delivery_qrcode,
      data: {
        order_id: r,
        delivery_type: o.data.delivery_type
      },
      success: function(t) {
        0 == t.code ? o.setData({
          hide: 0,
          qrcode: t.data.url
        }) : wx.showModal({
          title: "提示",
          content: t.msg
        });
      },
      complete: function() {
        wx.hideLoading();
      }
    });
  },
  hide: function(t) {
    this.setData({
      hide: 1
    });
  }
});